package lanou.autohome.findcar.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.findcar.beans.BrandBean;

/**
 * Created by dllo on 16/8/22.
 */
public class BrandAdapter extends RecyclerView.Adapter<BrandAdapter.BViewHolder>{

    private Context context;
    private BrandBean brandBeans;

    public BrandAdapter(Context context) {
        this.context = context;
    }

    public void setBrandBeans(BrandBean brandBeans) {
        this.brandBeans = brandBeans;
        notifyDataSetChanged();
    }

    @Override
    public BViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_findcar_brand, null);
        BViewHolder bViewHolder = new BViewHolder(view);
        return bViewHolder;
    }

    @Override
    public void onBindViewHolder(BViewHolder holder, int position) {
        holder.name.setText(brandBeans.getResult().getList().get(position).getName());

        NetTool netTool = new NetTool();
        netTool.getImage(brandBeans.getResult().getList().get(position).getImg() , holder.img);

    }

    @Override
    public int getItemCount() {
        return brandBeans != null ? brandBeans.getResult().getList().size() : 0;
    }

    public class BViewHolder extends RecyclerView.ViewHolder {
        ImageView img ;
        TextView name;

        public BViewHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.imageview_brand_findcar_item);
            name = (TextView) itemView.findViewById(R.id.name_brand_findcar_item);
        }
    }
}
